package com.ruoyi.mstore.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.mstore.domain.Activity;
import com.ruoyi.mstore.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activity")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /**
     * 根据条件查询活动信息
     *
     * @param activity 查询条件对象
     * @return 符合条件的活动列表
     */
    @GetMapping("/list")
    public List<Activity> list(Activity activity) {
        return activityService.getByActivity(activity);
    }


    /**
     * 新增活动
     */
    @PostMapping("/add")
    public R<Boolean> addActivity(@RequestBody Activity activity) {
        boolean result = activityService.addActivity(activity);
        return R.ok(result);
    }

    /**
     * 修改活动
     */
    @PutMapping("/update")
    public R<Boolean> updateActivity(@RequestBody Activity activity) {
        boolean result = activityService.updateActivity(activity);
        return R.ok(result);
    }

    /**
     * 删除活动
     */
    @DeleteMapping("/delete/{activityId}")
    public R<Boolean> deleteActivity(@PathVariable Long activityId) {
        boolean result = activityService.deleteActivity(activityId);
        return R.ok(result);
    }
}